package saucaca.Adapter;

import java.util.ArrayList;
import java.util.List;

import saucaca.Object.TopicObject;
import saucaca.Util.AppController;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.lemon.kenhnhacvn.BaseActivity;
import com.lemon.kenhnhacvn.R;

public class TopicAdapter extends ArrayAdapter<TopicObject> {
	Context context;
	List<TopicObject> data = new ArrayList<TopicObject>();
	ImageLoader imageLoader;
	String isType;
	public TopicAdapter(Context context, List<TopicObject> data) {
		super(context, R.layout.item_topic_gridview, data);
		this.context = context;
		this.data = data;

	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		RecordHolder holder = null;
		if (row == null) {
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			row = inflater.inflate(R.layout.item_topic_gridview, parent, false);
			holder = new RecordHolder();
			holder.txtTitle = (TextView) row.findViewById(R.id.custom_view_album_artist);
			holder.imageItem = (ImageView) row.findViewById(R.id.custom_view_album_image);
			holder.imageItem.setLayoutParams(BaseActivity.linear_params_4);
			row.setTag(holder);
		} else {
			holder = (RecordHolder) row.getTag();
		}
		TopicObject item = data.get(position);
		holder.txtTitle.setText(item.getTXNAME());
//		imageLoader.displayImage(item.getAVATAR(), holder.imageItem, options);
		try {
			imageLoader=((BaseActivity)context).imageLoader;
		} catch (Exception e) {
			imageLoader=AppController.getInstance().getImageLoader();
		}
		
		imageLoader.get(item.getAVATAR(), ImageLoader.getImageListener( holder.imageItem,
	         R.drawable.ic_default, R.drawable.ic_default));
		
		return row;
	}

	static class RecordHolder {
		TextView txtTitle;
		ImageView imageItem;
	}
}
